import requests
import base64

cookies = {
    'HMACCOUNT': '9F47B428D92F550C',
    'Hm_lvt_9bcbda9cbf86757998a2339a0437208e': '1720709647',
    'no-alert3': 'true',
    'tk': '601100958127505223',
    'sessionid': '1r4gcnrvb338naa18vz7nb8dwuax270r',
    'Hm_lvt_c99546cf032aaa5a679230de9a95c7db': '1720709646,1720793980',
    'm': '9b3590f7b28c919a5a845a151b1c121a|1720952574000',
    'Hm_lpvt_9bcbda9cbf86757998a2339a0437208e': '1720953090',
    'Hm_lpvt_c99546cf032aaa5a679230de9a95c7db': '1720953363',
}

headers = {
    'authority': 'match.yuanrenxue.cn',
    'accept': 'application/json, text/javascript, */*; q=0.01',
    'accept-language': 'zh-CN,zh;q=0.9',
    # 'cookie': 'HMACCOUNT=9F47B428D92F550C; Hm_lvt_9bcbda9cbf86757998a2339a0437208e=1720709647; no-alert3=true; tk=601100958127505223; sessionid=1r4gcnrvb338naa18vz7nb8dwuax270r; Hm_lvt_c99546cf032aaa5a679230de9a95c7db=1720709646,1720793980; m=9b3590f7b28c919a5a845a151b1c121a|1720952574000; Hm_lpvt_9bcbda9cbf86757998a2339a0437208e=1720953090; Hm_lpvt_c99546cf032aaa5a679230de9a95c7db=1720953363',
    'referer': 'https://match.yuanrenxue.cn/match/12',
    'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"macOS"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    'x-requested-with': 'XMLHttpRequest',
}

params = {
    'page': '1',
    'm': 'eXVhbnJlbnh1ZTE=',
}


def get_base64(data: int):
    data = 'yuanrenxue' + str(data)
    return str(base64.b64encode(data.encode('utf-8')), 'utf-8')


rst = 0
for i in range(1, 6):
    params['page'] = str(i)
    params['m'] = get_base64(i)
    print(params['m'])

    response = requests.get('https://match.yuanrenxue.cn/api/match/12', params=params, cookies=cookies, headers=headers).json()
    if response['state'] != "success":
        print('error:', params)
        break
    for item in response['data']:
        rst += item['value']

print(rst)

